//
//  CameraListCell.m
//  HaiKangDemo
//
//  Created by 崔 on 16/10/1.
//  Copyright © 2016年 崔. All rights reserved.
//

#import "CameraListCell.h"
//#import <UIImageView+WebCache.h>
#import "SDWebImage/UIImageView+WebCache.h"

#import "LGControllerManager.h"

#import "relevanceInfo.h"

#import <SVProgressHUD.h>

#import "ALSHeader.h"

@interface CameraListCell()

@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UIImageView *onLineView;
//添加关联
@property (weak, nonatomic) IBOutlet UIButton *addRelevance;
@property (weak, nonatomic) IBOutlet UILabel *doorInfoLable;

//验证是否是管理员
@property (assign, nonatomic) BOOL administrators;

@end

@implementation CameraListCell


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    UIImageView *backImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"点击栏"]];
    
    [self setBackgroundView:backImage];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    //超级管理员验证
    self.administrators = NSUDIsAdministrators;
}

//添加关联按钮事件(关联门)
- (IBAction)addDoorInfoClick:(UIButton *)sender {
    
    //如果不是管理员,会弹出警告
    if (!self.administrators) {
        [self administratorPresentation];
        return;
    }
    LGControllerManager *controllerM = [LGControllerManager shareControllerManager];
    
    NSArray *controllers = controllerM.controllers;
    
    //给关联按钮绑定tag
    self.relevanceBtn.tag = self.tag;
    
    //通知代理
    if ([self.delegate respondsToSelector:@selector(CameraListCell:withControllers:andBtnIndex:)]) {
        
        [self.delegate CameraListCell:self withControllers:controllers andBtnIndex:self.relevanceBtn.tag];
    }
    
}
//非法管理弹窗弹窗
- (void)administratorPresentation {
    [SVProgressHUD showInfoWithStatus:@"请联系管理员"];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
    });
}
- (void)setCameraInfo:(EZCameraInfo *)cameraInfo{
    
    _cameraInfo = cameraInfo;
    
    if (cameraInfo.isOnline) {
        
        self.onLineView.hidden = YES;
        
    } else{
        
         self.onLineView.hidden = NO;
        
    }
    
    if (cameraInfo.picUrl) {
        
        [self.iconView sd_setImageWithURL:[NSURL URLWithString:cameraInfo.picUrl]];
        
    }
    
    self.camerInfoLable.text = @"海康萤石系列";
    
    if (self.relevanceInfo == nil) {
        
        self.doorInfoLable.text = @"无关联门";
        
        [self.addRelevance setTitle:@"添加关联" forState:UIControlStateNormal];
        
        
        
        
    } else{
    
    self.doorInfoLable.text = self.relevanceInfo.doorName;
    
//    self.addRelevance.titleLabel.text = @"修改门";
        
    [self.addRelevance setTitle:@"修改关联" forState:UIControlStateNormal];
        
    }
    
}

@end
